import os

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app

class Welcome(webapp.RequestHandler):
  def get(self):
    
    if users.get_current_user():
      url = users.create_logout_url(self.request.uri)
      url_linktext = 'Logout'
      
      path = os.path.join(os.path.dirname(__file__), 'views/welcome.html')
      settings_template = os.path.join(os.path.dirname(__file__), 'views/settings_view.html')
      
      template_values = {
        'account_name': users.get_current_user(),
        'url': url,
        'url_linktext': url_linktext,
        'settings_template': settings_template
        }
        
      self.response.out.write(template.render(path, template_values))
    else:
      self.redirect(users.create_login_url(self.request.uri))
    
application = webapp.WSGIApplication(
                                     [('/', Welcome)],
                                     debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()
